﻿using System;
using System.ComponentModel;
using System.IO;
using System.Threading;
using Microsoft.WowAddonStudio.Project.Import;
using Microsoft.WowAddonStudio.Project.Import.Ace;
using Microsoft.WowAddonStudio.Project.Import.Folder;
using NUnit.Framework;

namespace WowProjectPackage.Tests.Import
{
	/// <summary>
	/// Class that implements test cases for testing <see cref="ImportProcess"/> class.
	/// </summary>
	[TestFixture]
	public class ImportProcessTest : ProjectBuilderTest
	{
		#region Setup/Teardown

		[SetUp]
		public override void SetUp()
		{
			base.SetUp();
			progressCounter = 0;
			processFinishedEvent = new AutoResetEvent(false);
		}

		#endregion

		private int progressCounter;
		private AutoResetEvent processFinishedEvent;

		private void process_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
		{
			processFinishedEvent.Set();
		}

		private void process_ProgressChanged(object sender, ProgressChangedEventArgs e)
		{
			++progressCounter;
		}

		[Test]
		public void TestAbakusImportProcess()
		{
			var process = new ImportProcess(aceImporter, new AceImportSettings(abakusUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 6);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "Abakus-r64376");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 4);
		}

		[Test]
		public void TestAbakusImportProcessCancel()
		{
			var process = new ImportProcess(aceImporter, new AceImportSettings(abakusUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 6);
		}

		[Test]
		public void TestAce3ImportProcess()
		{
			var process = new ImportProcess(aceImporter, new AceImportSettings(ace3Uri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 105);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "Ace3-r69511");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 8);
		}

		[Test]
		public void TestAce3ImportProcessCancel()
		{
			var process = new ImportProcess(aceImporter, new AceImportSettings(ace3Uri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 105);
		}

		[Test]
		public void TestChinchillaAceImportProcess()
		{
			var process = new ImportProcess(aceImporter, new AceImportSettings(chinchillaUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 88);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "Chinchilla-r68297");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 7);
		}

		[Test]
		public void TestChinchillaAceImportProcessCancel()
		{
			var process = new ImportProcess(aceImporter, new AceImportSettings(chinchillaUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 88);
		}

		[Test]
		public void TestDeadlyBossModsDBMApiImportProcess()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_API"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 31);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_API");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 15);
			targetFolder = Path.Combine(targetFolder, "Textures");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 14);
		}

		[Test]
		public void TestDeadlyBossModsDBMApiImportProcessCancel()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_API"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 31);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_API");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 15);
			targetFolder = Path.Combine(targetFolder, "Textures");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 14);
		}

		[Test]
		public void TestDeadlyBossModsDBMBattlegroundsImportProcess()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_Battlegrounds"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 15);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_Battlegrounds");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 13);
		}

		[Test]
		public void TestDeadlyBossModsDBMBattlegroundsImportProcessCancel()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_Battlegrounds"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 15);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_Battlegrounds");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 13);
		}

		[Test]
		public void TestDeadlyBossModsDBMBlackTempleImportProcess()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_BlackTemple"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 17);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_BlackTemple");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 15);
		}

		[Test]
		public void TestDeadlyBossModsDBMBlackTempleImportProcessCancel()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_BlackTemple"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 17);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_BlackTemple");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 15);
		}

		[Test]
		public void TestDeadlyBossModsDBMGUIImportProcess()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_GUI"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 13);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_GUI");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 11);
		}

		[Test]
		public void TestDeadlyBossModsDBMGUIImportProcessCancel()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_GUI"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 13);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_GUI");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 11);
		}

		[Test]
		public void TestDeadlyBossModsDBMHyjalImportProcess()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_Hyjal"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 14);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_Hyjal");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 12);
		}

		[Test]
		public void TestDeadlyBossModsDBMHyjalImportProcessCancel()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_Hyjal"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 14);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_Hyjal");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 12);
		}

		[Test]
		public void TestDeadlyBossModsDBMKarazhanImportProcess()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_Karazhan"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 23);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_Karazhan");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 21);
		}

		[Test]
		public void TestDeadlyBossModsDBMKarazhanImportProcessCancel()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_Karazhan"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 23);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_Karazhan");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 21);
		}

		[Test]
		public void TestDeadlyBossModsDBMOutlandsImportProcess()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_Outlands"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 15);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_Outlands");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 13);
		}

		[Test]
		public void TestDeadlyBossModsDBMOutlandsImportProcessCancel()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_Outlands"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 15);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_Outlands");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 13);
		}

		[Test]
		public void TestDeadlyBossModsDBMSerpentshrineImportProcess()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_Serpentshrine"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 23);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_Serpentshrine");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 21);
		}

		[Test]
		public void TestDeadlyBossModsDBMSerpentshrineImportProcessCancel()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_Serpentshrine"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 23);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_Serpentshrine");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 21);
		}

		[Test]
		public void TestDeadlyBossModsDBMSunwellImportProcess()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_Sunwell"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 16);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_Sunwell");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 14);
		}

		[Test]
		public void TestDeadlyBossModsDBMSunwellImportProcessCancel()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_Sunwell"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 16);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_Sunwell");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 14);
		}

		[Test]
		public void TestDeadlyBossModsDBMTheEyeImportProcess()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_TheEye"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 12);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_TheEye");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 10);
		}

		[Test]
		public void TestDeadlyBossModsDBMTheEyeImportProcessCancel()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_TheEye"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 12);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_TheEye");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 10);
		}

		[Test]
		public void TestDeadlyBossModsDBMZulAmanImportProcess()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_ZulAman"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 14);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_ZulAman");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 12);
		}

		[Test]
		public void TestDeadlyBossModsDBMZulAmanImportProcessCancel()
		{
			var deadlyBossSrc = new Uri(Path.Combine(deadlyBossUri.LocalPath, "DBM_ZulAman"));
			var process = new ImportProcess(importer, new FolderImportSettings(deadlyBossSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 14);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "DBM_ZulAman");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 12);
		}

		[Test]
		public void TestEmptyFolderImportProcess()
		{
			var process = new ImportProcess(importer, new FolderImportSettings(emptyUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 1);
			Assert.AreEqual(
				Directory.GetFiles(targetUri.LocalPath).Length, 0);
		}

		[Test]
		public void TestEmptyFolderImportProcessCancel()
		{
			var process = new ImportProcess(importer, new FolderImportSettings(emptyUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 1);
			Assert.LessOrEqual(
				Directory.GetFiles(targetUri.LocalPath).Length, 0);
		}

		[Test]
		[ExpectedException(typeof (ArgumentNullException))]
		public void TestImportProcessEmptyPath()
		{
			new ImportProcess(aceImporter, null, string.Empty);
		}

		[Test]
		[ExpectedException(typeof (ArgumentNullException))]
		public void TestImportProcessNullPath()
		{
			new ImportProcess(aceImporter, null, null);
		}

		[Test]
		[ExpectedException(typeof (ArgumentNullException))]
		public void TestImportProcessNullPlugin()
		{
			new ImportProcess(null, null, null);
		}

		[Test]
		public void TestInFlightAceImportProcess()
		{
			var process = new ImportProcess(aceImporter, new AceImportSettings(inFlightUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 16);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "InFlight-r68765");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 7);
		}

		[Test]
		public void TestInFlightAceImportProcessCancel()
		{
			var process = new ImportProcess(aceImporter, new AceImportSettings(inFlightUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 16);
		}

		[Test]
		public void TestOutfitterImportProcess()
		{
			var process = new ImportProcess(importer, new FolderImportSettings(outfitterUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 44);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "Outfitter");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 17);

			string docFolder = Path.Combine(targetFolder, "Documentation");
			Assert.IsTrue(Directory.Exists(docFolder));
			Assert.AreEqual(Directory.GetFiles(docFolder).Length, 3);

			docFolder = Path.Combine(docFolder, "Images");
			Assert.IsTrue(Directory.Exists(docFolder));
			Assert.AreEqual(Directory.GetFiles(docFolder).Length, 7);

			string textFolder = Path.Combine(targetFolder, "Textures");
			Assert.IsTrue(Directory.Exists(textFolder));
			Assert.AreEqual(Directory.GetFiles(textFolder).Length, 15);
		}

		[Test]
		public void TestOutfitterImportProcessCancel()
		{
			var process = new ImportProcess(importer, new FolderImportSettings(outfitterUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 44);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "Outfitter");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 17);

			string docFolder = Path.Combine(targetFolder, "Documentation");
			Assert.IsTrue(Directory.Exists(docFolder));
			Assert.LessOrEqual(Directory.GetFiles(docFolder).Length, 3);

			docFolder = Path.Combine(docFolder, "Images");
			Assert.IsTrue(Directory.Exists(docFolder));
			Assert.LessOrEqual(Directory.GetFiles(docFolder).Length, 7);

			string textFolder = Path.Combine(targetFolder, "Textures");
			Assert.IsTrue(Directory.Exists(textFolder));
			Assert.LessOrEqual(Directory.GetFiles(textFolder).Length, 15);
		}

		[Test]
		public void TestPlainFolderImportProcess()
		{
			var process = new ImportProcess(importer, new FolderImportSettings(plainUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 6);
			Assert.AreEqual(
				Directory.GetFiles(Path.Combine(targetUri.LocalPath, "MyFirstWowAddon")).Length, 4);
		}

		[Test]
		public void TestPlainFolderImportProcessCancel()
		{
			var process = new ImportProcess(importer, new FolderImportSettings(plainUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 6);
			Assert.LessOrEqual(
				Directory.GetFiles(Path.Combine(targetUri.LocalPath, "MyFirstWowAddon")).Length, 4);
		}

		[Test]
		public void TestRealisticFolderImportProcess()
		{
			var process = new ImportProcess(importer, new FolderImportSettings(realisticUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 14);
			Assert.AreEqual(
				Directory.GetFiles(Path.Combine(targetUri.LocalPath, "OpponentAnalyzer")).Length, 9);
		}

		[Test]
		public void TestRealisticFolderImportProcessCancel()
		{
			var process = new ImportProcess(importer, new FolderImportSettings(realisticUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 14);
			Assert.LessOrEqual(
				Directory.GetFiles(Path.Combine(targetUri.LocalPath, "OpponentAnalyzer")).Length, 9);
		}

		[Test]
		public void TestRecursiveFolderImportProcess()
		{
			var process = new ImportProcess(importer, new FolderImportSettings(recursiveUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 6);
			Assert.AreEqual(
				Directory.GetFiles(Path.Combine(targetUri.LocalPath, "MyFirstWowAddon")).Length, 3);
		}

		[Test]
		public void TestRecursiveFolderImportProcessCancel()
		{
			var process = new ImportProcess(importer, new FolderImportSettings(recursiveUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 6);
			Assert.LessOrEqual(
				Directory.GetFiles(Path.Combine(targetUri.LocalPath, "MyFirstWowAddon")).Length, 3);
		}

		[Test]
		public void TestShamanWarningAceImportProcess()
		{
			var process = new ImportProcess(aceImporter, new AceImportSettings(shamanWarningUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 24);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "ShamanWarning-r65770");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 4);
		}

		[Test]
		public void TestShamanWarningAceImportProcessCancel()
		{
			var process = new ImportProcess(aceImporter, new AceImportSettings(shamanWarningUri),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 24);
		}

		[Test]
		public void TestSWStatsImportProcess()
		{
			var swStatsSrc = new Uri(Path.Combine(swStatsUri.LocalPath, "SW_Stats"));
			var process = new ImportProcess(importer, new FolderImportSettings(swStatsSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 58);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "SW_Stats");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 26);

			targetFolder = Path.Combine(targetFolder, "images");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 30);
		}

		[Test]
		public void TestSWStatsImportProcessCancel()
		{
			var swStatsSrc = new Uri(Path.Combine(swStatsUri.LocalPath, "SW_Stats"));
			var process = new ImportProcess(importer, new FolderImportSettings(swStatsSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 58);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "SW_Stats");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 26);

			targetFolder = Path.Combine(targetFolder, "images");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 30);
		}

		[Test]
		public void TestSWStatsProfilesImportProcess()
		{
			var swStatsSrc = new Uri(Path.Combine(swStatsUri.LocalPath, "SW_Stats_Profiles"));
			var process = new ImportProcess(importer, new FolderImportSettings(swStatsSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 6);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "SW_Stats_Profiles");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 4);
		}

		[Test]
		public void TestSWStatsProfilesImportProcessCancel()
		{
			var swStatsSrc = new Uri(Path.Combine(swStatsUri.LocalPath, "SW_Stats_Profiles"));
			var process = new ImportProcess(importer, new FolderImportSettings(swStatsSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 6);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "SW_Stats_Profiles");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 4);
		}

		[Test]
		public void TestSWUniLogImportProcess()
		{
			var swStatsSrc = new Uri(Path.Combine(swStatsUri.LocalPath, "SW_UniLog"));
			var process = new ImportProcess(importer, new FolderImportSettings(swStatsSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.AreEqual(progressCounter, 8);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "SW_UniLog");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.AreEqual(Directory.GetFiles(targetFolder).Length, 6);
		}

		[Test]
		public void TestSWUniLogImportProcessCancel()
		{
			var swStatsSrc = new Uri(Path.Combine(swStatsUri.LocalPath, "SW_UniLog"));
			var process = new ImportProcess(importer, new FolderImportSettings(swStatsSrc),
			                                targetUri.LocalPath);
			process.ProgressChanged += process_ProgressChanged;
			process.RunWorkerCompleted += process_RunWorkerCompleted;
			process.RunWorkerAsync();
			process.CancelAsync();
			processFinishedEvent.WaitOne();

			//Execution is finished
			Assert.LessOrEqual(progressCounter, 8);
			//Check that directory exists...
			string targetFolder = Path.Combine(targetUri.LocalPath, "SW_UniLog");
			Assert.IsTrue(Directory.Exists(targetFolder));
			Assert.LessOrEqual(Directory.GetFiles(targetFolder).Length, 6);
		}
	}
}